<template>
  <div class="p-2">
    <el-form
      :model="form"
      inline
      label-width="180"
      label-position="right"
      ref="formRef"
      :rules="rules"
    >
      <el-card>
        <template #header>
          <div class="card-header">
            <span>*基础信息(准确真实填写企业基础信息)</span>
          </div>
        </template>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item
              label="企业名称："
              required
              prop="name"
            >
              <el-input
                v-model="form.name"
                clearable
                placeholder="请输入企业名称"
                @change="nameChange"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="企业简称："
              required
              prop="nameNc"
            >
              <el-input
                v-model="form.nameNc"
                clearable
                placeholder="请输入企业简称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="支付通道："
              required
              prop="passage"
            >
              <el-select
                v-model="form.passage"
                placeholder="请选择支付通道"
                clearable
                filterable
              >
                <el-option
                  v-for="(item,i) in pay_channel"
                  :label="item.label"
                  :value="item.value"
                  :key="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="统一社会信用代码："
              required
              prop="nsrSbh"
            >
              <el-input
                v-model="form.nsrSbh"
                clearable
                placeholder="请输入统一社会信用代码"
                @change="nsrSbhChange"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="法人姓名："
              required
              prop="fr"
            >
              <el-input
                v-model="form.fr"
                clearable
                placeholder="请输入法人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="法人身份证号："
              required
              prop="frSfz"
            >
              <el-input
                v-model="form.frSfz"
                clearable
                placeholder="请输入法人身份证号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="法人手机号："
              required
              prop="frSjh"
            >
              <el-input
                v-model="form.frSjh"
                clearable
                placeholder="请输入法人手机号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人姓名："
              required
              prop="wtr"
            >
              <el-input
                v-model="form.wtr"
                clearable
                placeholder="请输入经办人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人身份证号码："
              required
              prop="wtrSfz"
            >
              <el-input
                v-model="form.wtrSfz"
                clearable
                placeholder="请输入经办人身份证号码"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人电话："
              required
              prop="wtrSjh"
            >
              <el-input
                v-model="form.wtrSjh"
                clearable
                placeholder="请输入经办人电话"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人邮箱："
              required
              prop="wtrEmail"
            >
              <el-input
                v-model="form.wtrEmail"
                clearable
                placeholder="请输入经办人邮箱"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="区域："
              required
              prop="unitArea"
            >
              <el-cascader
                v-model="form.unitArea"
                :props="unitAreaNameOptions"
                @change="handleChangeAreaName"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="实际经营地址："
              required
              prop="address"
            >
              <el-input
                v-model="form.address"
                clearable
                placeholder="请输入实际经营地址"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="所属行业："
              required
              prop="industryCode"
            >
              <el-cascader
                v-model="form.industryCode"
                clearable
                :options="industryOptions"
                @change="handleChangeCode"
                placeholder="请选择所属行业"
              />
            </el-form-item>
          </el-col>
          <!--
          <el-col :span="8">
            <el-form-item
              label="营业执照有效期："
              required
              prop="yyzzTime"
            >
              <el-date-picker
                v-model="form.yyzzTime"
                clearable
                type="daterange"
                value-format="YYYY-MM-DD"
                range-separator="~"
                start-placeholder="请选择开始时间"
                end-placeholder="请选择结束时间"
              />
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item
              label="法人身份证有效期："
              required
              prop="frCardidTime"
            >
              <el-date-picker
                v-model="form.frCardidTime"
                clearable
				unlink-panels="true"
                type="daterange"
                value-format="YYYY-MM-DD"
                range-separator="~"
                start-placeholder="请选择开始时间"
                end-placeholder="请选择结束时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人身份证有效期："
              required
              prop="jbrCardidTime"
            >
              <el-date-picker
                v-model="form.jbrCardidTime"
                clearable
				unlink-panels="true"
                type="daterange"
                value-format="YYYY-MM-DD"
                range-separator="~"
                start-placeholder="请选择开始时间"
                end-placeholder="请选择结束时间"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务员：">
              <el-select
                v-model="form.ywyId"
                placeholder="请选择业务员"
                clearable
                filterable
              >
                <el-option
                  v-for="(item,i) in salesmanList"
                  :label="item.name"
                  :value="item.id"
                  :key="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="注册资本"
              required
              prop="registeredAssets"
            >
              <el-input
                v-model="form.registeredAssets"
                clearable
                placeholder="请输入注册资本"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item
              label="注册时间"
              required
              prop="regdate"
            >
              <el-date-picker
                v-model="form.regdate"
                clearable
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请输入注册时间"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <el-card>
        <template #header>
          <div class="card-header">
            <span>*账户信息(绑定账户必须为对公账户)</span>
          </div>
        </template>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="账户名称：">
              <el-input
                v-model="form.khm"
                clearable
                disabled
                placeholder="请输入账户名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="开户银行："
              required
              prop="khhCode"
            >
              <el-select
                v-model="form.khhCode"
                placeholder="请选择开户银行"
                clearable
                filterable
                @change="khhChange"
              >
                <el-option
                  v-for="(item,i) in bank_list"
                  :label="item.label"
                  :value="item.value"
                  :key="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="开户行："
              required
              prop="khd"
            >
              <el-input
                v-model="form.khd"
                clearable
                placeholder="格式：***银行***市***支行"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="联行号："
              required
              prop="khhNo"
            >
              <el-input
                v-model="form.khhNo"
                clearable
                placeholder="请输入联行号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="银行账号："
              required
              prop="bankCard"
            >
              <el-input
                v-model="form.bankCard"
                clearable
                placeholder="请输入银行账号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="基本存款账户编号："
              required
              prop="jbckzhbm"
            >
              <el-input
                v-model="form.jbckzhbm"
                clearable
                placeholder="请输入基本存款账户编号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <el-card>
        <template #header>
          <div class="card-header">
            <span>*开票信息(录入企业开票信息)</span>
          </div>
        </template>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item
              label="发票抬头："
              required
              prop="invoceHeader"
            >
              <el-input
                v-model="form.invoceHeader"
                clearable
                disabled
                placeholder="请输入发票抬头"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="纳税人识别号："
              required
              prop="invoceCreditCode"
            >
              <el-input
                v-model="form.invoceCreditCode"
                clearable
                disabled
                placeholder="请输入纳税人识别号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="开户行："
              required
              prop="invoceBankName"
            >
              <el-input
                v-model="form.invoceBankName"
                clearable
                placeholder="格式：***银行***市***支行"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="银行账号："
              required
              prop="invoceBankCard"
            >
              <el-input
                v-model="form.invoceBankCard"
                clearable
                placeholder="请输入银行账号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="单位注册地址："
              required
              prop="invoceAddress"
            >
              <el-input
                v-model="form.invoceAddress"
                clearable
                placeholder="请输入单位注册地址"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="单位电话："
              required
              prop="invoceDwdh"
            >
              <el-input
                v-model="form.invoceDwdh"
                clearable
                placeholder="请输入单位电话"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <el-card>
        <template #header>
          <div class="card-header">
            <span>企业资质[上传图片格式仅支持png/jpg,大小不得超过2M]</span>
          </div>
        </template>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item
              label="营业执照照片："
              required
              prop="yyzz"
            >
              <imageUpload
                v-model="form.yyzz"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="开户许可证："
              required
              prop="fhxkzPic"
            >
              <imageUpload
                v-model="form.fhxkzPic"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="法人身份证正面："
              required
              prop="frSfzzm"
            >
              <imageUpload
                v-model="form.frSfzzm"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="法人身份证反面："
              required
              prop="frSfzfm"
            >
              <imageUpload
                v-model="form.frSfzfm"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人身份证正面："
              required
              prop="jbrSfzzm"
            >
              <imageUpload
                v-model="form.jbrSfzzm"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="经办人身份证反面："
              required
              prop="jbrSfzfm"
            >
              <imageUpload
                v-model="form.jbrSfzfm"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <el-card>
        <template #header>
          <div class="card-header">
            <span>经营场所[上传图片格式仅支持png/jpg,大小不得超过2M]</span>
          </div>
        </template>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item
              label="门头全景照："
              required
              prop="mtqjzPic"
            >
              <imageUpload
                v-model="form.mtqjzPic"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="办公照片："
              required
              prop="bgzp1Pic"
            >
              <imageUpload
                v-model="form.bgzp1Pic"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="办公照片："
              required
              prop="bgzp2Pic"
            >
              <imageUpload
                v-model="form.bgzp2Pic"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <el-card>
        <template #header>
          <div class="card-header">
            <span>补充材料[上传图片格式仅支持png/jpg,大小不得超过2M]</span>
          </div>
        </template>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item
              label="业务场景真实性承诺函："
              required
              prop="ywcjzsxcnh"
            >
              <imageUpload
                v-model="form.ywcjzsxcnh"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="业务场景说明："
              required
              prop="ywcjsm"
            >
              <imageUpload
                v-model="form.ywcjsm"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="法大大授权协议："
              required
              prop="fddsqxy"
            >
              <imageUpload
                v-model="form.fddsqxy"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="特殊行业许可证：">
              <imageUpload
                v-model="form.tshyxkz"
                modelKey="url"
                :limit="1"
                :isShowTip="false"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div class="footer">
          <el-popconfirm
            title="确定放弃编辑？"
            @confirm="proxy?.$router.go(-1)"
          >
            <template #reference>
              <el-button>取消</el-button>
            </template>
          </el-popconfirm>
          <el-button
            :loading="buttonLoading"
            type="primary"
            @click="submitForm"
          >确 定</el-button>
        </div>
      </el-card>
    </el-form>
  </div>
</template>

<script setup name="addOrEditEnterprise" lang="ts">
import api from '@/api/enterprise/addEnterprise';
import { selListVo, areaVo, addOrEditForm } from '@/api/enterprise/addEnterprise/types';
import { SalesmanVO } from '@/api/system/salesman/types';

const props = defineProps({
  merchantId: {
    type: String,
    default: ''
  }
});

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { pay_channel, bank_list } = toRefs<any>(proxy?.useDict('pay_channel', 'bank_list'));

const industryOptions = ref([]);
const salesmanList = ref<SalesmanVO[]>();
const formRef = ref<ElFormInstance>();

const form = ref<addOrEditForm>({
  address: '',
  bankCard: '',
  bgzp1Pic: '',
  bgzp2Pic: '',
  fddsqxy: '',
  fhxkzPic: '',
  fr: '',
  frCardidBeginDate: '',
  frCardidEndDate: '',
  frSfz: '',
  frSfzfm: '',
  frSfzzm: '',
  frSjh: '',
  industry: '',
  regdate:'',
  registeredAssets:'',
  industryCode: '',
  invoceAddress: '',
  invoceBankCard: '',
  invoceBankName: '',
  invoceCreditCode: '',
  invoceDwdh: '',
  invoceHeader: '',
  jbckzhbm: '',
  jbrCardidBeginDate: '',
  jbrCardidEndDate: '',
  jbrSfzfm: '',
  jbrSfzzm: '',
  khd: '',
  khh: '',
  khhCode: '',
  khhNo: '',
  khm: '',
  mtqjzPic: '',
  name: '',
  nameNc: '',
  nsrSbh: '',
  passage: '',
  tshyxkz: '',
  unitArea: '',
  unitAreaName: '',
  wtr: '',
  wtrEmail: '',
  wtrSfz: '',
  wtrSjh: '',
  ywcjsm: '',
  ywcjzsxcnh: '',
  ywyId: '',
  yyzz: '',
  yyzzBeginDate: '',
  yyzzEndDate: '',
  yyzzTime: [],
  frCardidTime: [],
  jbrCardidTime: []
});

const rules = ref({
  address: [{ required: true, message: '请输入实际经营地址', trigger: 'blur' }],
  bankCard: [{ required: true, message: '请输入银行账号', trigger: 'blur' }],
  bgzp1Pic: [{ required: true, message: '请上传办公照片1', trigger: 'change' }],
  bgzp2Pic: [{ required: true, message: '请上传办公照片2', trigger: 'change' }],
  // fddsqxy: [{ required: true, message: '请上传法大大授权协议', trigger: 'change' }],
  fhxkzPic: [{ required: true, message: '请上传开户许可证', trigger: 'change' }],
  fr: [{ required: true, message: '请输入法人姓名', trigger: 'blur' }],
  frCardidTime: [{ required: true, message: '请选择法人身份证有效期', trigger: 'change' }],
  frSfz: [{ required: true, message: '请输入法人身份证号', trigger: 'blur' }],
  frSfzfm: [{ required: true, message: '请上传法人身份证反面', trigger: 'change' }],
  frSfzzm: [{ required: true, message: '请上传法人身份证正面', trigger: 'change' }],
  frSjh: [{ required: true, pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的法人手机号', trigger: 'blur' }],
  industryCode: [{ required: true, message: '请选择所属行业', trigger: 'change' }],
  registeredAssets: [{ required: true, message: '请输入注册资金', trigger: 'blur' }],
  regdate: [{ required: true, message: '请选择注册时间', trigger: 'change' }],
  invoceAddress: [{ required: true, message: '请输入发票单位注册地址', trigger: 'blur' }],
  invoceBankCard: [{ required: true, message: '请输入发票开户银行账号', trigger: 'blur' }],
  invoceBankName: [{ required: true, message: '请输入发票开户银行名称', trigger: 'blur' }],
  invoceCreditCode: [{ required: true, message: '请输入发票纳税人识别号', trigger: 'blur' }],
  invoceDwdh: [{ required: true, message: '请输入发票单位电话', trigger: 'blur' }],
  invoceHeader: [{ required: true, message: '请输入发票抬头', trigger: 'blur' }],
  jbckzhbm: [{ required: true, message: '请输入基本存款账户编号', trigger: 'blur' }],
  jbrCardidTime: [{ required: true, message: '请选择经办人身份证有效期', trigger: 'change' }],
  jbrSfzfm: [{ required: true, message: '请上传经办人身份证反面', trigger: 'change' }],
  jbrSfzzm: [{ required: true, message: '请上传经办人身份证正面', trigger: 'change' }],
  khd: [{ required: true, message: '请输入开户行', trigger: 'blur' }],
  khhCode: [{ required: true, message: '请选择开户银行', trigger: 'change' }],
  khhNo: [{ required: true, message: '请输入联行号', trigger: 'blur' }],
  khm: [{ required: true, message: '请输入开户名', trigger: 'blur' }],
  mtqjzPic: [{ required: true, message: '请上传门头全景照', trigger: 'change' }],
  name: [{ required: true, message: '请输入企业名称', trigger: 'blur' }],
  nameNc: [{ required: true, message: '请输入企业简称', trigger: 'blur' }],
  nsrSbh: [{ required: true, message: '请输入统一社会信用代码', trigger: 'blur' }],
  passage: [{ required: true, message: '请选择支付通道', trigger: 'change' }],
  // tshyxkz: [{ required: true, message: '请上传特殊行业许可证', trigger: 'change' }],
  unitArea: [{ required: true, message: '请选择区域', trigger: 'change' }],
  wtr: [{ required: true, message: '请输入经办人姓名', trigger: 'blur' }],
  wtrEmail: [{ required: true, message: '请输入经办人邮件', trigger: 'blur' }],
  wtrSfz: [{ required: true, message: '请输入经办人身份证号', trigger: 'blur' }],
  wtrSjh: [{ required: true, pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的经办人手机号', trigger: 'blur' }],
  ywcjsm: [{ required: true, message: '请上传业务场景说明', trigger: 'change' }],
  ywcjzsxcnh: [{ required: true, message: '请上传业务场景真实性承诺函', trigger: 'change' }],
  yyzz: [{ required: true, message: '请上传营业执照图片', trigger: 'change' }],
  yyzzTime: [{ required: true, message: '请选择营业执照有效期', trigger: 'change' }]
});

const loading = ref(true);

const nameChange = (value: string) => {
  form.value.khm = value;
  form.value.invoceHeader = value;
};

const nsrSbhChange = (value: string) => {
  form.value.invoceCreditCode = value;
};

import type { CascaderProps, CascaderValue } from 'element-plus';
const unitAreaNameOptions: CascaderProps = {
  lazy: true,
  async lazyLoad(node, resolve) {
    const { level } = node;
    let nodes = [];
    var parentId = level == 0 ? 0 : node.data?.value;
    let res = await api.areaQueryList(parentId);
    nodes = res.data.map((item: areaVo) => {
      return {
        value: item.areaId,
        label: item.areaName,
        leaf: item.level >= 2 ? true : false
      };
    });
    resolve(nodes);
  }
};
const industryList = ref<any>([]);
const getIndustryCodeOptions = async () => {
  let res = await api.selList();
  res.data.forEach((e: any) => {
    industryList.value.push(e);
    if (e.children && e.children.length) {
      e.children.forEach((ce: any) => {
        industryList.value.push(ce);
      });
    }
  });
  industryOptions.value = res.data;
  console.log(industryList.value);
};
const getSalesmanList = async () => {
  let res = await api.channelSalesman();
  salesmanList.value = res.data;
};

const areaList = ref([]);
const handleChangeAreaName = async (value: CascaderValue) => {
  if (!areaList.value.length) {
    let res = await api.areaQueryList();
    areaList.value = res.data;
  }
  let arr: Array<string> = [];
  areaList.value.forEach((area: areaVo) => {
    (value as any).forEach((e: string | number) => {
      if (area.areaId == e) {
        arr.push(area.areaName);
      }
    });
  });
  form.value.unitAreaName = arr[0] + '/' + arr[1];
  console.log(form.value.unitArea);
  console.log(form.value.unitAreaName);
};
const handleChangeCode = (value: CascaderValue) => {
  let arr: Array<string> = [];
  industryList.value.forEach((area: selListVo) => {
    (value as any).forEach((e: string | number) => {
      if (area.value == e) {
        arr.push(area.label);
      }
    });
  });
  form.value.industry = arr[0] + '/' + arr[1];
  console.log(form.value.industry);
};
const khhChange = (value: any) => {
  console.log(value, bank_list);
  bank_list.value.forEach((e: any) => {
    if (e.value == value) {
      form.value.khh = e.label;
    }
  });
};
const route = useRoute();
/** 查询企业信息 */
const getInfoData = async () => {
  loading.value = true;
  const res = await api.merchantDetail(props.merchantId);
  loading.value = false;
  form.value = res.data;
  form.value.frCardidTime = [form.value.frCardidBeginDate, form.value.frCardidEndDate];
  form.value.jbrCardidTime = [form.value.jbrCardidBeginDate, form.value.jbrCardidEndDate];
  form.value.yyzzTime = [form.value.yyzzBeginDate, form.value.yyzzEndDate];
  if (form.value.industryCode) {
    let arr: any = form.value.industryCode ? form.value.industryCode?.split(',') : [];
    form.value.industryCode = arr;
  }
  if (form.value.unitArea) {
    let arr: any = form.value.unitArea ? form.value.unitArea?.split(',') : [];
    setTimeout(() => {
      arr = [parseInt(arr[0]), parseInt(arr[1])];
      form.value.unitArea = arr;
    }, 800);
  }
};
const buttonLoading = ref<boolean>(false);
const submitForm = () => {
  formRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      let obj = {
        ...form.value,
        frCardidBeginDate: form.value.frCardidTime[0],
        frCardidEndDate: form.value.frCardidTime[1],
        jbrCardidBeginDate: form.value.jbrCardidTime[0],
        jbrCardidEndDate: form.value.jbrCardidTime[1],
        yyzzBeginDate: form.value.yyzzTime[0],
        yyzzEndDate: form.value.yyzzTime[1],
        industryCode: form.value.industryCode?.toString(),
        unitArea: form.value.unitArea?.toString()
      };
      delete obj.frCardidTime;
      delete obj.jbrCardidTime;
      delete obj.yyzzTime;
      console.log(obj);
      let res = props.merchantId
        ? await api.editMerchant(obj).finally(() => (buttonLoading.value = false))
        : await api.addMerchant(obj).finally(() => (buttonLoading.value = false));
      console.log(res);
      proxy?.$modal.msgSuccess(res.msg);
      proxy?.$router.go(-1);
      proxy?.$tab.closePage(route);
    }
  });
};
onMounted(() => {
  if (props.merchantId) {
    getInfoData(); // 查询企业信息
  }
  getSalesmanList();
  getIndustryCodeOptions();
  console.log(pay_channel, bank_list);
});
</script>

<style lang="scss" scoped>
.el-card {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
  .el-form-item {
    width: 100%;

    .el-select {
      width: 100%;
    }
  }
}
.footer {
  text-align: center;
  padding: 36px 0 16px;
}
:deep(.el-cascader) {
  width: 100%;
}
</style>
